#include "Entry.h"
Entry* Entry::_instance = NULL;
Entry* Entry::getInstance() {
	if(_instance == NULL)
    {
		_instance = new Entry();
        return _instance;
    }
    else
    {
        return _instance;
    }
}

Entry::~Entry(void)
{
	delete _instance;
}

Entry::Entry(string name, string date, string time):_name(name)
{
	_endDate=QDate::fromString(QString::fromStdString(date),"dd/MM/yy");
	_endTime=QTime::fromString(QString::fromStdString(time), "hhmm");
}
Entry::Entry(string name, QDate endDate, QTime endTime) : _name(name), _endDate(endDate), _endTime(endTime)
{
}
Entry::Entry() {
}
//Entry::~Entry(void)
//{
//}
void Entry::setName(string name) {
	 _name = name;
}
void Entry::setEndDate(QDate endDate) {
	_endDate = endDate;
}
void Entry::setEndTime(QTime endTime) {
	_endTime=endTime;
}
bool Entry::isFloat() const{
	return (!getStartDate().isValid() && !getStartTime().isValid() && !getEndDate().isValid() && !getEndTime().isValid());
}
bool Entry::isEmpty() {
	return(_name == EMPTY_STRING);// && _endDate = EMPTY_DATE && _endTime = EMPTY_TIME);
}
QDate Entry::getEndDate() const {
	return _endDate;
}
QTime Entry::getEndTime() const {
	return _endTime;
}
string Entry::getName() const {
	return _name;
}
bool Entry::isPast(QDateTime target) const {
	if(getEndDate().isValid() && getEndTime().isValid()) {//valid endatetime
		return QDateTime(getEndDate(), getEndTime()) < target;//return if ended
	}else {
		return false;
	}
}
bool Entry::isSpanning() const {
	if(getStartDate().isValid() && getEndDate().isValid())
		return (getStartDate() != getEndDate());
	return false;
}
bool Entry::isOccuring(QDate target) const{
	if (getStartDate().isValid() && getEndDate().isValid()){
		if(target >= getStartDate() && target <= getEndDate()){//starts and ends today, starts before today
			return true;
		}
		else{
			return false;
		}
	}
	if (getStartDate().isValid()){ 
		if(target == getStartDate()){
			return true;
		}
		else{
			return false;
		}
	}
	if (getEndDate().isValid()){ 
		if(target == getEndDate()){
			return true;
		}
		else{
			return false;
		}
	}
}

const QDate Entry::EMPTY_DATE = QDate();
const QTime Entry::EMPTY_TIME = QTime();
const string Entry::EMPTY_STRING="";
const QString Entry::FORMAT_DATE = "ddMMyyyy";
const QString Entry::FORMAT_TIME = "hhmm";